
********************************************************************************
*Table A4; Column 1 
********************************************************************************
clear all
set matsize 10000
set maxvar 40000
set more off
global data " "
global dir " "
use $data/estimation_sample_including_dropouts_blacks, clear


preserve

gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4

gen d2=0
replace d2=1 if mothers_education<12

gen plus0d2=plus0*d2 
gen plus1d2=plus1*d2
gen plus2d2=plus2*d2 
gen plus3d2=plus3*d2 
gen plus4d2=plus4*d2 

g bytimesdr= by*d2
g bstatetimesdr=mom_birth_state*d2
g agetimesdr=age_cat*d2
g tbotimesdr =tbo*d2
g maletimesdr= male*d2
g yeartimesdr=year*d2
g birth_monthdr=birth_month*d2


foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*d2
}


global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}
reg newbw2500 $treat_var  d2  i.age_cat i.tbo i.male i.year i.birth_month i.division#c.by  $state_var  ///
i.bytimesdr i.bstatetimesdr i.agetimesdr i.yeartimesdr i.birth_monthdr  i.tbotimesdr i.maletimesdr i.by i.mom_birth_state, cluster(mom_birth_state)

local Z=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
lincom (_b[plus0]*meanplus0/`Z')+(_b[plus1]*meanplus1/`Z')+(_b[plus2]*meanplus2/`Z')+(_b[plus3]*meanplus3/`Z')+(_b[plus4]*meanplus4/`Z')

local U=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
lincom (_b[plus0d2]*meanplus0d2/`U')+(_b[plus1d2]*meanplus1d2/`U')+(_b[plus2d2]*meanplus2d2/`U')+(_b[plus3d2]*meanplus3d2/`U')+(_b[plus4d2]*meanplus4d2/`U')
restore

********************************************************************************
set seed 23260513
capture postclose placebo	
postfile placebo c_weighted d_weighted using "$data/table_a4_c1", replace
forvalues i=1/500 {
use $data/estimation_sample_including_dropouts_blacks, clear


preserve
bsample, cluster(mom_birth_state)

gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4

gen d2=0
replace d2=1 if mothers_education<12

gen plus0d2=plus0*d2 
gen plus1d2=plus1*d2
gen plus2d2=plus2*d2 
gen plus3d2=plus3*d2 
gen plus4d2=plus4*d2 

g bytimesdr= by*d2
g bstatetimesdr=mom_birth_state*d2
g agetimesdr=age_cat*d2
g tbotimesdr =tbo*d2
g maletimesdr= male*d2
g yeartimesdr=year*d2
g birth_monthdr=birth_month*d2


foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*d2
}

global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}

qui reg newbw2500 $treat_var  d2  i.age_cat i.tbo i.male i.year i.birth_month i.division#c.by  $state_var  i.bytimesdr i.bstatetimesdr i.agetimesdr i.yeartimesdr i.birth_monthdr  i.tbotimesdr i.maletimesdr i.by i.mom_birth_state
local V=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
local V_int=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
local c_weighted=(_b[plus0]*meanplus0/`V')+(_b[plus1]*meanplus1/`V')+(_b[plus2]*meanplus2/`V')+(_b[plus3]*meanplus3/`V')+(_b[plus4]*meanplus4/`V')
local d_weighted=(_b[plus0d2]*meanplus0d2/`V_int')+(_b[plus1d2]*meanplus1d2/`V_int')+(_b[plus2d2]*meanplus2d2/`V_int')+(_b[plus3d2]*meanplus3d2/`V_int')+(_b[plus4d2]*meanplus4d2/`V_int')
post placebo (`c_weighted') (`d_weighted')
restore
}
postclose placebo


use table_a4_c1, clear

sum  /****Std Dev is the standard error of the weighted point estimate.*/






********************************************************************************
*Table A4; Column 2 
********************************************************************************
clear all
set matsize 10000
set maxvar 40000
set more off
global data " "
global dir " "
use $data/estimation_sample_including_dropouts_blacks, clear


preserve

gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4

gen d2=0
replace d2=1 if mothers_education<12

gen plus0d2=plus0*d2 
gen plus1d2=plus1*d2
gen plus2d2=plus2*d2 
gen plus3d2=plus3*d2 
gen plus4d2=plus4*d2 

g bytimesdr= by*d2
g bstatetimesdr=mom_birth_state*d2
g agetimesdr=age_cat*d2
g tbotimesdr =tbo*d2
g maletimesdr= male*d2
g yeartimesdr=year*d2
g birth_monthdr=birth_month*d2


foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*d2
}


global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}
reg newpretermLT37 $treat_var  d2  i.age_cat i.tbo i.male i.year i.birth_month i.division#c.by  $state_var  ///
i.bytimesdr i.bstatetimesdr i.agetimesdr i.yeartimesdr i.birth_monthdr  i.tbotimesdr i.maletimesdr i.by i.mom_birth_state, cluster(mom_birth_state)

local Z=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
lincom (_b[plus0]*meanplus0/`Z')+(_b[plus1]*meanplus1/`Z')+(_b[plus2]*meanplus2/`Z')+(_b[plus3]*meanplus3/`Z')+(_b[plus4]*meanplus4/`Z')

local U=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
lincom (_b[plus0d2]*meanplus0d2/`U')+(_b[plus1d2]*meanplus1d2/`U')+(_b[plus2d2]*meanplus2d2/`U')+(_b[plus3d2]*meanplus3d2/`U')+(_b[plus4d2]*meanplus4d2/`U')
restore

********************************************************************************
set seed 23260513
capture postclose placebo	
postfile placebo c_weighted d_weighted using "$data/table_a4_c2", replace
forvalues i=1/500 {
use $data/estimation_sample_including_dropouts_blacks, clear


preserve
bsample, cluster(mom_birth_state)

gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4

gen d2=0
replace d2=1 if mothers_education<12

gen plus0d2=plus0*d2 
gen plus1d2=plus1*d2
gen plus2d2=plus2*d2 
gen plus3d2=plus3*d2 
gen plus4d2=plus4*d2 

g bytimesdr= by*d2
g bstatetimesdr=mom_birth_state*d2
g agetimesdr=age_cat*d2
g tbotimesdr =tbo*d2
g maletimesdr= male*d2
g yeartimesdr=year*d2
g birth_monthdr=birth_month*d2


foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*d2
}

global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}

qui reg newpretermLT37 $treat_var  d2  i.age_cat i.tbo i.male i.year i.birth_month i.division#c.by  $state_var  i.bytimesdr i.bstatetimesdr i.agetimesdr i.yeartimesdr i.birth_monthdr  i.tbotimesdr i.maletimesdr i.by i.mom_birth_state
local V=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
local V_int=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
local c_weighted=(_b[plus0]*meanplus0/`V')+(_b[plus1]*meanplus1/`V')+(_b[plus2]*meanplus2/`V')+(_b[plus3]*meanplus3/`V')+(_b[plus4]*meanplus4/`V')
local d_weighted=(_b[plus0d2]*meanplus0d2/`V_int')+(_b[plus1d2]*meanplus1d2/`V_int')+(_b[plus2d2]*meanplus2d2/`V_int')+(_b[plus3d2]*meanplus3d2/`V_int')+(_b[plus4d2]*meanplus4d2/`V_int')
post placebo (`c_weighted') (`d_weighted')
restore
}
postclose placebo


use table_a4_c2, clear

sum  /****Std Dev is the standard error of the weighted point estimate.*/



********************************************************************************
*Table A4; Column 3 
********************************************************************************
clear all
set matsize 10000
set maxvar 40000
use $data/estimation_sample_including_dropouts_whites, clear


preserve

gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4

gen d2=0
replace d2=1 if mothers_education<12

gen plus0d2=plus0*d2 
gen plus1d2=plus1*d2
gen plus2d2=plus2*d2 
gen plus3d2=plus3*d2 
gen plus4d2=plus4*d2 

g bytimesdr= by*d2
g bstatetimesdr=mom_birth_state*d2
g agetimesdr=age_cat*d2
g tbotimesdr =tbo*d2
g maletimesdr= male*d2
g yeartimesdr=year*d2
g birth_monthdr=birth_month*d2


foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*d2
}


global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}
reg newbw2500 $treat_var  d2  i.age_cat i.tbo i.male i.year i.birth_month i.division#c.by  $state_var  ///
i.bytimesdr i.bstatetimesdr i.agetimesdr i.yeartimesdr i.birth_monthdr  i.tbotimesdr i.maletimesdr i.by i.mom_birth_state, cluster(mom_birth_state)

local Z=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
lincom (_b[plus0]*meanplus0/`Z')+(_b[plus1]*meanplus1/`Z')+(_b[plus2]*meanplus2/`Z')+(_b[plus3]*meanplus3/`Z')+(_b[plus4]*meanplus4/`Z')

local U=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
lincom (_b[plus0d2]*meanplus0d2/`U')+(_b[plus1d2]*meanplus1d2/`U')+(_b[plus2d2]*meanplus2d2/`U')+(_b[plus3d2]*meanplus3d2/`U')+(_b[plus4d2]*meanplus4d2/`U')
restore

********************************************************************************
set seed 23260513
capture postclose placebo	
postfile placebo c_weighted d_weighted using "$data/table_a4_c3", replace
forvalues i=1/500 {
use $data/estimation_sample_including_dropouts_whites, clear


preserve
bsample, cluster(mom_birth_state)

gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4

gen d2=0
replace d2=1 if mothers_education<12

gen plus0d2=plus0*d2 
gen plus1d2=plus1*d2
gen plus2d2=plus2*d2 
gen plus3d2=plus3*d2 
gen plus4d2=plus4*d2 

g bytimesdr= by*d2
g bstatetimesdr=mom_birth_state*d2
g agetimesdr=age_cat*d2
g tbotimesdr =tbo*d2
g maletimesdr= male*d2
g yeartimesdr=year*d2
g birth_monthdr=birth_month*d2


foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*d2
}

global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}

qui reg newbw2500 $treat_var  d2  i.age_cat i.tbo i.male i.year i.birth_month i.division#c.by  $state_var  i.bytimesdr i.bstatetimesdr i.agetimesdr i.yeartimesdr i.birth_monthdr  i.tbotimesdr i.maletimesdr i.by i.mom_birth_state
local V=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
local V_int=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
local c_weighted=(_b[plus0]*meanplus0/`V')+(_b[plus1]*meanplus1/`V')+(_b[plus2]*meanplus2/`V')+(_b[plus3]*meanplus3/`V')+(_b[plus4]*meanplus4/`V')
local d_weighted=(_b[plus0d2]*meanplus0d2/`V_int')+(_b[plus1d2]*meanplus1d2/`V_int')+(_b[plus2d2]*meanplus2d2/`V_int')+(_b[plus3d2]*meanplus3d2/`V_int')+(_b[plus4d2]*meanplus4d2/`V_int')
post placebo (`c_weighted') (`d_weighted')
restore
}
postclose placebo


use table_a4_c3, clear

sum  /****Std Dev is the standard error of the weighted point estimate.*/






********************************************************************************
*Table A4; Column 4 
********************************************************************************
clear all
set matsize 10000
set maxvar 40000
use $data/estimation_sample_including_dropouts_whites, clear


preserve

gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4

gen d2=0
replace d2=1 if mothers_education<12

gen plus0d2=plus0*d2 
gen plus1d2=plus1*d2
gen plus2d2=plus2*d2 
gen plus3d2=plus3*d2 
gen plus4d2=plus4*d2 

g bytimesdr= by*d2
g bstatetimesdr=mom_birth_state*d2
g agetimesdr=age_cat*d2
g tbotimesdr =tbo*d2
g maletimesdr= male*d2
g yeartimesdr=year*d2
g birth_monthdr=birth_month*d2


foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*d2
}


global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}
reg newpretermLT37 $treat_var  d2  i.age_cat i.tbo i.male i.year i.birth_month i.division#c.by  $state_var  ///
i.bytimesdr i.bstatetimesdr i.agetimesdr i.yeartimesdr i.birth_monthdr  i.tbotimesdr i.maletimesdr i.by i.mom_birth_state, cluster(mom_birth_state)

local Z=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
lincom (_b[plus0]*meanplus0/`Z')+(_b[plus1]*meanplus1/`Z')+(_b[plus2]*meanplus2/`Z')+(_b[plus3]*meanplus3/`Z')+(_b[plus4]*meanplus4/`Z')

local U=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
lincom (_b[plus0d2]*meanplus0d2/`U')+(_b[plus1d2]*meanplus1d2/`U')+(_b[plus2d2]*meanplus2d2/`U')+(_b[plus3d2]*meanplus3d2/`U')+(_b[plus4d2]*meanplus4d2/`U')
restore

********************************************************************************
set seed 23260513
capture postclose placebo	
postfile placebo c_weighted d_weighted using "$data/table_a4_c4", replace
forvalues i=1/500 {
use $data/estimation_sample_including_dropouts_whites, clear


preserve
bsample, cluster(mom_birth_state)

gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4

gen d2=0
replace d2=1 if mothers_education<12

gen plus0d2=plus0*d2 
gen plus1d2=plus1*d2
gen plus2d2=plus2*d2 
gen plus3d2=plus3*d2 
gen plus4d2=plus4*d2 

g bytimesdr= by*d2
g bstatetimesdr=mom_birth_state*d2
g agetimesdr=age_cat*d2
g tbotimesdr =tbo*d2
g maletimesdr= male*d2
g yeartimesdr=year*d2
g birth_monthdr=birth_month*d2


foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*d2
}

global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}

qui reg newpretermLT37 $treat_var  d2  i.age_cat i.tbo i.male i.year i.birth_month i.division#c.by  $state_var  i.bytimesdr i.bstatetimesdr i.agetimesdr i.yeartimesdr i.birth_monthdr  i.tbotimesdr i.maletimesdr i.by i.mom_birth_state
local V=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
local V_int=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
local c_weighted=(_b[plus0]*meanplus0/`V')+(_b[plus1]*meanplus1/`V')+(_b[plus2]*meanplus2/`V')+(_b[plus3]*meanplus3/`V')+(_b[plus4]*meanplus4/`V')
local d_weighted=(_b[plus0d2]*meanplus0d2/`V_int')+(_b[plus1d2]*meanplus1d2/`V_int')+(_b[plus2d2]*meanplus2d2/`V_int')+(_b[plus3d2]*meanplus3d2/`V_int')+(_b[plus4d2]*meanplus4d2/`V_int')
post placebo (`c_weighted') (`d_weighted')
restore
}
postclose placebo


use table_a4_c4, clear

sum  /****Std Dev is the standard error of the weighted point estimate.*/
